class ExaminationResoultsController  < ApplicationController

  active_scaffold :examination_resoult do |config|
    config.label = " Wyniki"
    config.actions.exclude :update, :delete, :create

    config.columns = [
            :examination_number,
            :updated_at,
            :user,
            :executing_user,
            :order_examination,
            :param_resoults
    ]

    columns[:examination_number].label = "Nr badania"
    columns[:updated_at].label = "Wykonano"
    columns[:user].label = "Sprawdzający"
    columns[:user].clear_link
    columns[:executing_user].label = "Wykonujacy"
    
    config.columns[:order_examination].form_ui  = :select
    config.columns[:param_resoults].form_ui  = :select

    columns[:executing_user].clear_link
    columns[:examination_number].label = "Nr badania:"
    columns[:updated_at].label = "Wykonano:"
    columns[:user].label = "Sprawdzający:"
    columns[:executing_user].label = "Wykonujacy:"
    columns[:order_examination].label = "Rodzaj badania:"
    columns[:param_resoults].label = "Wyniki parametrów:"

    

    config.list.columns.exclude :order_examination,  :param_resoults
    config.action_links.add 'email_sent', :label => 'Wyślij wyniki', :type => :record, :page => false,  :security_method => :email_authorized?
  end

  def email_sent

    @resoult = ExaminationResoult.find(params[:id])
    @patient = PatientData.find(1)
    ExaminationMailer::deliver_mail(PatientData.find(1), ExaminationResoult.find(params[:id]))

  end

  def email_authorized?
    (current_user.roles.detect { |role| role.id == 2 })
  end


end

